Use case: encryption/decryption in DMA mode

Sequence diagram

Encryption/decryption in DMA mode

  @startuml

  participant "Application" as App
  participant "CRYP" as CRYP

  note over App,CRYP: Encryption
  App -> CRYP: HAL_CRYP_Encrypt_DMA()

  group opt
  note over App,CRYP: Tag generation
  App -> CRYP: HAL_CRYPEx_AESGCM_GenerateAuthTAG()
  note right: **Only for GCM algorithm**
  App -> CRYP: HAL_CRYPEx_AESCCM_GenerateAuthTAG()
  note right: **Only for CCM algorithm**
  end group

  note over App,CRYP: Decryption
  App -> CRYP: HAL_CRYP_Decrypt_DMA()

  group opt
  note over App,CRYP: Tag generation
  App -> CRYP: HAL_CRYPEx_AESGCM_GenerateAuthTAG()
  note right: **Only for GCM algorithm**
  App -> CRYP: HAL_CRYPEx_AESCCM_GenerateAuthTAG()
  note right: **Only for CCM algorithm**
  end group

  @enduml

Code snippet

HAL1

HAL2

/* Encryption */
HAL_CRYP_Encrypt_DMA(&hcryp, Plaintext, PLAINTEXT_SIZE,
                 EncryptedText);

/* Only for GCM algorithm */
HAL_CRYPEx_AESGCM_GenerateAuthTAG(&hcryp,TAG,
                                TIMEOUT_VALUE);

/* Only for CCM algorithm */
HAL_CRYPEx_AESCCM_GenerateAuthTAG(&hcryp,TAG,
                                TIMEOUT_VALUE);

/* Decryption */
HAL_CRYP_Decrypt_DMA(&hcryp,Ciphertext , PLAINTEXT_SIZE,
                 DecryptedText);

/* Only for GCM algorithm */
HAL_CRYPEx_AESGCM_GenerateAuthTAG(&hcryp,TAG,
                                TIMEOUT_VALUE);

/* Only for CCM algorithm */
HAL_CRYPEx_AESCCM_GenerateAuthTAG(&hcryp,TAG,
                                TIMEOUT_VALUE);
/* Encryption */
HAL_AES_Encrypt_DMA(&haes, Plaintext, PLAINTEXT_SIZE ,
                                       EncryptedText);

/* Only for GCM algorithm */
HAL_AES_GCM_GenerateAuthTAG(&haes,TAG,
                              TIMEOUT_VALUE);

/* Only for CCM algorithm */
HAL_AES_CCM_GenerateAuthTAG(&haes,TAG,
                             TIMEOUT_VALUE);

/* Decryption */
HAL_AES_Decrypt_DMA(&haes, Ciphertext, PLAINTEXT_SIZE ,
                                        DecryptedText);

/* Only for GCM algorithm */
HAL_AES_GCM_GenerateAuthTAG(&haes,TAG,
                              TIMEOUT_VALUE);

/* Only for CCM algorithm */
HAL_AES_CCM_GenerateAuthTAG(&haes,TAG,
                             TIMEOUT_VALUE);

Key changes

  1. DMA-mode APIs are renamed from HAL_CRYP_*_DMA to HAL_AES_*_DMA.

  2. Tag generation APIs are renamed from HAL_CRYPEx_AES* to HAL_AES_* for GCM and CCM algorithms.